﻿/* Adapted from the Aquiles project: http://aquiles.codeplex.com/. */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.Cassandra;
using Lucandra.Net.Connection.Endpoint;
using Thrift.Transport;
using Thrift.Protocol;

namespace Lucandra.Net.Connection
{
    /// <summary>
    /// This is a placeholder that can be adapted in the event that we want to implement a real connection factory
    /// with different transports.
    /// </summary>
    internal static class CassandraConnectionFactory
    {
        internal static CassandraClient Create(CassandraEndpoint endpoint)
        {
            TSocket socket;
            if (endpoint.Timeout == 0)
                socket = new TSocket(endpoint.Host, endpoint.Port);
            else
                socket = new TSocket(endpoint.Host, endpoint.Port, endpoint.Timeout);
            var transport = new TFramedTransport(socket);
            var protocol = new TBinaryProtocol(transport);
            var client = new Cassandra.Client(protocol);

            return new CassandraClient(client, endpoint);
        }
    }
}
